<template>
  <div v-if="isVisible" class="modal">
    <div class="modal-content">
      <span class="close" @click="closeModal">&times;</span>
      <slot></slot> <!-- 使用插槽来传递内容 -->
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const isVisible = ref(false);

function closeModal() {
  isVisible.value = false;
}

function showModal() {
  isVisible.value = true;
}

defineExpose({ showModal, closeModal });
</script>

<style scoped>
.modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: white;
  padding: 20px;
  border-radius: 10px;
  position: relative;
  width: 50%;
  min-height: 65%;
  max-height: 80%;
  top:5%;
  flex-wrap: wrap; /* 允许内容换行显示 */
  box-shadow: 0 4px 8px rgba(0,0,0,0.5);
  display: flex;
}

.close {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 24px;
  cursor: pointer;
}
</style>
